package cn.chitanda.weather.data

import cn.chitanda.weather.data.network.NetWorkService
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

const val TAG = "tags"

class WeatherRepository private constructor(private val network: NetWorkService) {

    suspend fun refreshWeather(location: String) = requestWeather(location)

    private suspend fun requestWeather(location: String) = withContext(Dispatchers.IO) {
        val heWeather = network.fetchWeather(location)
        // val weather = heWeather.weather!![0]
        heWeather.weather!![0]
    }

    companion object {
        private var instance: WeatherRepository? = null
        fun getInstance(network: NetWorkService) = instance ?: synchronized(this) {
            WeatherRepository(network).also { instance = it }
        }
    }

}